package br.elsa.survey.services.listeners.tests;

import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;

import org.junit.Before;
import org.junit.Test;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;

import br.elsa.survey.services.events.QuestionCreatedEvent;
import br.elsa.survey.services.events.QuestionRemovedEvent;
import br.elsa.survey.services.listeners.QuestionEventListener;
import br.elsa.survey.statistics.Statistics;

public class QuestionListenerTest {

	/**
	 * Class under test
	 */
	private QuestionEventListener questionListener;

	@Mock
	private Statistics statistics;

	@Mock
	private QuestionCreatedEvent questionCreatedEvent;

	@Mock
	private QuestionRemovedEvent questionRemovedEvent;

	@Before
	public void setUp() throws Exception {
		MockitoAnnotations.initMocks(this);
		this.questionListener = new QuestionEventListener(statistics);
	}

	@Test
	public void onQuestionCreatedShouldLoadStatisticsInformation() {

		questionListener.onQuestionCreated(questionCreatedEvent);
		verify(statistics, times(1)).loadStatistics();
	}

	@Test
	public void onQuestionRemovedShouldLoadStatisticsInformation() {

		questionListener.onQuestionRemoved(questionRemovedEvent);
		verify(statistics, times(1)).loadStatistics();
	}
}
